home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_12_11 / ALLISON / EXHAUST2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-04  |  598 b   |  33 lines

  1. LISTING 18 - Restores traditional "return-null" behavior
  2. // exhaust2.cpp
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5. #include <new.h>
  6. #include <assert.h>
  7.  
  8. main()
  9. {
  10.     set_new_handler(0);
  11.  
  12.     for (int i = 0; ; ++i)
  13.     {
  14.         double *dp = new double[100];
  15.         if ((i+1)%10 == 0)
  16.             cout << (i+1) << " allocations" << endl;
  17.         assert(dp);
  18.     }
  19. }
  20.  
  21. /* Output:
  22. 10 allocations
  23. 20 allocations
  24. 30 allocations
  25. 40 allocations
  26. 50 allocations
  27. 60 allocations
  28. 70 allocations
  29. Assertion failed: dp, file exhaust3.cpp, line 15
  30. Abnormal program termination
  31. */
  32.  
  33.